<?php
/**
*作用:
*说明:
*版权:
*作者:Red	QQ:316765128
*时间:2011/7/28
**/
include_once './include/init.inc.php';
include_once './include/pinyin.func.php';


//red add
$cp = empty($_GET['cp'])?'a':strtolower($_GET['cp']);
$dp = empty($_GET['dp'])?'a':strtolower($_GET['dp']);
if(strlen($cp) != 1 or strlen($dp) != 1){
	exit('error!');
}
$dog_all = $db->fetch_all("select `goods_name`,`goods_id`,`original_img` from `info_goods` WHERE cat_id in ('2','64','65','66')");
$dogs = array();
$i=0;
foreach($dog_all as $key=>$val){
	$pinyin = Pinyin($val['goods_name']);
	$firstWord = substr($pinyin, 0, 1);
	if($dp == $firstWord or ($dp == 'z' and $val['goods_name'] == '藏獒')){
		if($dp == 'c' and $val['goods_name'] == '藏獒'){
			
		}else{
			$attr = array();
			$attr = get_goods_properties($val['goods_id'],$db); //属性
			$val['attr'] = @array_reverse($attr['pro']['商品属性']);
			$val['attr'] = @array_slice($val['attr'], 0, 4);
			if($i==4){
				$i = 0;
			}
			$val['num'] = $i;
			$dogs[] = $val;
			++$i;
		}
	}
}
$smarty->assign('dogs',       $dogs);
$smarty->assign('dog_num',       count($dog_all));

$cat_all = $db->fetch_all("select `goods_name`,`goods_id`,`original_img` from `info_goods` WHERE cat_id in ('3')");
$cats = array();
$i=0;
foreach($cat_all as $key=>$val){
	$pinyin = Pinyin($val['goods_name']);
	$firstWord = substr($pinyin, 0, 1);
	if($cp == $firstWord){
		$attr = array();
		$attr = get_goods_properties($val['goods_id'],$db); //属性
		$val['attr'] = @array_reverse($attr['pro']['商品属性']);
		$val['attr'] = @array_slice($val['attr'], 0, 4);
		if($i==4){
			$i = 0;
		}
		$val['num'] = $i;
		$cats[] = $val;
		++$i;
	}
}
$smarty->assign('cats',       $cats);
$smarty->assign('cat_num',       count($cat_all));

$pins = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$dog_pin = $cat_pin = '';
if(empty($_GET['cp'])){
	$_GET['cp'] = 'A';
}
if(empty($_GET['dp'])){
	$_GET['dp'] = 'A';
}
foreach($pins as $key=>$val){
	if($_GET['dp']==$val){
		$dog_pin .= '<li class="selebg">'.$val.'</li>';
	}elseif(in_array($val, array('E','I','O','U','V'))){
		$dog_pin .= '<li style="color:#ccc">'.$val.'</li>';
	}else{
		$dog_pin .= '<li><a href="./index.php?dp='.$val.'&cp='.$_GET['cp'].'">'.$val.'</a></li>';
	}
}
foreach($pins as $key=>$val){
	if($_GET['cp']==$val){
		$cat_pin .= '<li class="selebg">'.$val.'</li>';
	}elseif(in_array($val, array('C','F','G','I','M','P','Q','U','V','W'))){
		$cat_pin .= '<li style="color:#ccc">'.$val.'</li>';
	}else{
		$cat_pin .= '<li><a href="./index.php?dp='.$_GET['dp'].'&cp='.$val.'#cat">'.$val.'</a></li>';
	}
}
$smarty->assign('dog_pin',       $dog_pin);
$smarty->assign('cat_pin',       $cat_pin);
//red end

//
//openid:6D61E701EE71C2DB8A4349E06037697B   用户唯一标识
//token:4779433470145743562   具有访问权限的token
//secret:hMxbVBnciauf89h8   密钥

fheader();
$smarty->display('index.dwt');
ffooter();